<style lang="less">
  @import '../styles/common.less';
  @import '../tables/components/table.less';
</style>

<template>
  <div>
    <Row :gutter="10">
      <Card>
        <div class="table-head">
          <Select v-model="typeSelectid" :transfer="true" @on-change="onChangeTypeSelect" style="width:200px">
            <Option v-for="item in typeSelect" :value="item.id" :key="item.id">{{ item.name }}</Option>
          </Select>

          <Button type="primary" class="Button" @click="ExportData()">导出数据</Button>
          <Button type="primary" class="Button" @click="importData()">导入数据</Button>
          <a href="/vendors/Excel/record.xlsx" download="经济档案导入模板.xlsx">
            <Button type="primary" class="Button">下载模板</Button>
          </a>
          <Button type="primary" class="Button" @click="remove()">删除</Button>
          <Button type="primary" class="Button" @click="add()">添加</Button>
          <Button type="primary" class="Button" @click="showCommitteeModal()"
                  v-if="typeSelectid == 'undistributed'">任务分配
          </Button>
        </div>
        <Row class="margin-top-10">
          <Table stripe border :columns="columns" :data="data" @on-row-click="onRowData"
                 @on-selection-change="selectionChange"></Table>
        </Row>
        <div style="margin: 10px;overflow: hidden;height: 36px;">
          <div style="float: right;">
            <Page :total="total" :current="page" @on-change="changePage" show-elevator></Page>
          </div>
        </div>
      </Card>
      <Modal :width="600" title="详情"
             v-model="showCurrentTableData"
             ok-text="确定"
             cancel-text="取消"
             @on-ok=""
             @on-cancel=""
             class-name="vertical-center-modal"
             class="Modal-Detail-div">
        <Form label-position="top">
          <FormItem label="企业名称">
            <div class="dataDetail-div" v-text="dataDetail.name"></div>
          </FormItem>
          <FormItem label="企业成立时间" v-if="dataDetail.create_time">
            <div class="dataDetail-div" v-text="dataDetail.create_time"></div>
          </FormItem>
          <FormItem label="法人" v-if="dataDetail.boss">
            <div class="dataDetail-div" v-text="dataDetail.boss"></div>
          </FormItem>
          <FormItem label="手机号" v-if="dataDetail.mobile">
            <div class="dataDetail-div" v-text="dataDetail.mobile"></div>
          </FormItem>
          <FormItem label="信息采集地址" v-if="dataDetail.address">
            <div class="dataDetail-div" v-text="dataDetail.address"></div>
          </FormItem>
          <FormItem label="企业地址" v-if="dataDetail.company_address">
            <div class="dataDetail-div" v-text="dataDetail.company_address"></div>
          </FormItem>
          <FormItem label="企业规模" v-if="dataDetail.scale">
            <div class="dataDetail-div" v-text="dataDetail.scale"></div>
          </FormItem>
          <FormItem label="营业执照编号" v-if="dataDetail.idcard">
            <div class="dataDetail-div" v-text="dataDetail.idcard"></div>
          </FormItem>
          <FormItem label="营业执照有效期" v-if="dataDetail.period">
            <div class="dataDetail-div" v-text="dataDetail.period"></div>
          </FormItem>
          <FormItem label="所属居委会" v-if="dataDetail.department">
            <div class="dataDetail-div" v-text="dataDetail.department ? dataDetail.department.name : ''"></div>
          </FormItem>
          <FormItem label="状态" v-if="dataDetail.statusTitle">
            <div class="dataDetail-div" v-text="dataDetail.statusTitle"></div>
          </FormItem>
          <FormItem label="营业执照" v-if="dataDetail.license && dataDetail.license.length > 0">
            <div class="dataDetail-div">
              <img v-for="el in dataDetail.license" :src="el.path" class="img">
            </div>
          </FormItem>
          <FormItem label="其他图片" v-if="dataDetail.accessory && dataDetail.accessory.length > 0">
            <div class="dataDetail-div">
              <img v-for="el in dataDetail.accessory" :src="el.path" class="img">
            </div>
          </FormItem>
        </Form>
      </Modal>
      <!--编辑-->
      <Modal v-model="addCurrentTableData" :width="600" :mask-closable="false" :closable="false"
             class-name="vertical-center-modal" class="Modal-Detail-div">
        <h3 slot="header" style="color:#2D8CF0">编辑</h3>
        <Form label-position="top">
          <FormItem label="企业名称">
            <Input v-model="addData.name" placeholder="企业名称"></Input>
          </FormItem>
          <FormItem label="法人姓名">
            <Input v-model="addData.boss" placeholder="法人姓名"></Input>
          </FormItem>
          <FormItem label="联系方式">
            <Input v-model="addData.mobile" placeholder="联系方式"></Input>
          </FormItem>
          <FormItem label="企业规模">
            <InputNumber :max="1000000" :min="1" v-model="addData.scale" class="InputNumber"></InputNumber>
          </FormItem>
          <FormItem label="企业地址">
            <Input v-model="addData.company_address" placeholder="企业地址"></Input>
          </FormItem>
          <FormItem label="营业执照编号">
            <Input v-model="addData.company_idcard" placeholder="营业执照编号"></Input>
          </FormItem>
          <FormItem label="企业创立时间">
            <DatePicker type="date"
                        format="yyyy年MM月dd日"
                        :confirm="true"
                        :transfer="true"
                        :editable="false"
                        placement="bottom-start"
                        placeholder="请选择企业创立时间"
                        v-model="addData.create_time"
                        style="width: 100%;"></DatePicker>
          </FormItem>
          <FormItem label="营业执照有效期">
            <DatePicker type="date"
                        format="yyyy年MM月dd日"
                        :confirm="true"
                        :transfer="true"
                        :editable="false"
                        placement="bottom-start"
                        placeholder="请选择营业执照有效期"
                        v-model="addData.company_period"
                        style="width: 100%;"></DatePicker>
          </FormItem>
          <FormItem label="信息是否完善">
            <i-switch v-model="addData.is_complete" size="large">
              <span slot="open">是</span>
              <span slot="close">否</span>
            </i-switch>
          </FormItem>
          <FormItem label="营业执照">
            <div class="dataDetail-div chooseUser accessory">
              <img v-for="el in addData.license" :src="el.path" class="img">
              <Upload
                  :before-upload="handleUpload_license" action="" accept="image/*" :format="format"
                  :multiple="false">
                <Button icon="ios-cloud-upload-outline">选择文件</Button>
              </Upload>
            </div>
          </FormItem>
          <FormItem label="其他图片">
            <div class="dataDetail-div chooseUser accessory">
              <img v-for="el in addData.accessory" :src="el.path" class="img">
              <Upload
                  :before-upload="handleUpload_accessory" action="" accept="image/*" :format="format"
                  :multiple="true">
                <Button icon="ios-cloud-upload-outline">选择文件</Button>
              </Upload>
            </div>
          </FormItem>
        </Form>
        <div slot="footer">
          <Button type="text" @click="hideAddModal">取消</Button>
          <Button type="primary" :loading="saveLoading" @click="save()">确定</Button>
        </div>
      </Modal>
      <!--导入-->
      <Modal v-model="importDataModal" :width="600" :mask-closable="false" :closable="false"
             class-name="vertical-center-modal" class="Modal-Detail-div">
        <h3 slot="header" style="color:#2D8CF0">导入信息</h3>
        <Form label-position="top">
          <FormItem label="上传附件">
            <div class="dataDetail-div chooseUser accessory">
              <div class="users" v-for="el in importDataArr">
                <span class="span-name" v-text="el.name"></span>
                <span class="span-icon" @click="ImportDatadelimportData(el)">
                  <Icon type="close-round"></Icon>
                </span>
              </div>
              <Upload v-if="importDataArr.length == 0"
                      :before-upload="ImportDatahandleUpload" action="">
                <Button icon="ios-cloud-upload-outline">选择文件</Button>
              </Upload>
            </div>
          </FormItem>
          <FormItem label="预览" v-if="ImportData.length > 0">
            <div class="dataDetail-div dataDetail-div-padding-0">
              <Table stripe border :columns="ImportDataColumns" :data="ImportData" height="360"></Table>
            </div>
          </FormItem>
        </Form>
        <div slot="footer">
          <Button type="text" @click="hideImportDataModal">取消</Button>
          <Button type="primary" :loading="saveLoading" @click="saveImportData()">确定</Button>
        </div>
      </Modal>
      <!--任务分配居委会-->
      <Modal v-model="CommitteeModal" :width="600" :mask-closable="false" :closable="false"
             class-name="vertical-center-modal" class="Modal-Detail-div Modal-Detail-height">
        <h3 slot="header" style="color:#2D8CF0">任务分配</h3>
        <Form label-position="top">
          <FormItem label="居委会">
            <Select v-model="Committee_id" :transfer="true">
              <Option v-for="item in CommitteeList" :value="item.id" :key="item.id">{{ item.name }}</Option>
            </Select>
          </FormItem>
        </Form>
        <div slot="footer">
          <Button type="text" @click="hideCommitteeModal">取消</Button>
          <Button type="primary" :loading="saveLoading" @click="saveCommitteeData()">确定</Button>
        </div>
      </Modal>
    </Row>
  </div>
</template>

<script>
  import Cookies from 'js-cookie';
  import Util from '../../libs/util';
  import Utils from '../../libs/mod.utils';
  import String from '../../libs/mod.string';
  import Modal from '../../libs/mod.Modal';
  export default {
    components: {},
    data () {
      return {
        total: 0,
        page: 1,
        size: 10,
        id: '',
        typeSelectid: '',
        typeSelect: [
          {
            id: '',
            name: '全部'
          },
          {
            id: 'undistributed',
            name: '未分配'
          },
          {
            id: 'undo',
            name: '未录入'
          },
          {
            id: 'doing',
            name: '未完善'
          },
          {
            id: 'done',
            name: '已完成'
          },
        ],
        searchConName: '',
        searchConTel: '',
        showCurrentTableData: false,
        loading: true,
        showCurrentColumns: [],
        editInlineAndCellData: [],
        columns: [
          {
            type: 'selection',
            width: 60,
            align: 'center'
          },
          {
            key: 'name',
            title: '企业名称',
          },
          {
            key: 'create_time',
            title: '企业成立时间',
          },
          {
            key: 'address',
            title: '信息采集地址',
          },
          {
            key: 'company_address',
            title: '企业地址',
          },
          {
            key: 'status',
            title: '状态',
            width: 100,
            render: (h, params) => {
              var status = params.row.status;
              switch (status) {
                case 'undistributed':
                  status = '未分配';
                  break;
                case 'undo':
                  status = '未录入';
                  break;
                case 'doing':
                  status = '未完善';
                  break;
                case 'done':
                  status = '已完成';
                  break;
                default:
                  break;
              }
              return h('div', [
                h('span', status)
              ]);
            }
          },
          {
            title: 'Action',
            key: 'action',
            width: 150,
            align: 'center',
            render: (h, params) => {
              return h('div', [
                h('Button', {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    marginRight: '5px'
                  },
                  on: {
                    click: e => {
                      e.stopPropagation();
                      var data = params.row;
                      this.update(data, params.index);
                    }
                  }
                }, '修改')
              ]);
            }
          }
        ],
        data: [],
        dataDetail: {},
        initTable: [],
        format: Util.constant.format,
        addCurrentTableData: false,
        saveLoading: false,
        ajaxType: 'add',
        addData: {
          name: '',
          boss: '',
          mobile: '',
          scale: 1,
          create_time: '',
          company_address: '',
          company_idcard: '',
          company_period: '',
          license: [],
          is_complete: false,
          accessory: [],
        },
        selectionArr: [],
        importDataModal: false,
        importDataArr: [],
        CommitteeModal: false,
        Committee_id: '',//居委会
        CommitteeList: [],
        ImportDataColumns: [],
        ImportData: [],
      };
    },
    mounted () {
      this.getData();
      this.getCommitteeList();
    },
    methods: {
      onChangeTypeSelect: function (val) {
        var _this = this;
        _this.typeSelectid = val;
        _this.page = 1;
        _this.getData();
      },
      getData () {
        var _this = this;
        var data = {
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
          page: _this.page,
          size: _this.size,
          type: _this.typeSelectid,
        };
        var params = {
          url: '/record/list',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data || [];
            _this.total = res.rows;
            _this.data = _data;
            _this.selectionArr = [];
          } else {
            _this.$Message.error('查询信息失败!');
          }
        }
      },
      //居委会列表
      getCommitteeList: function () {
        var _this = this;
        var data = {};
        var params = {
          url: '/department/committee',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data.children || [];
            _this.Committee_id = '';
            _this.CommitteeList = _data;
          } else {
            _this.$Message.error('查询居委会信息失败!');
          }
        }
      },
      //识别营业执照
      getBusinessLicense: function (fid) {
        var _this = this;
        var data = {
          fid: fid
        };
        var params = {
          url: '/vender/baidu/getIdCard',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data || [];
            var dataStr = _data.data || '';
            if (dataStr != '') {
              var resData = Util.toJson(dataStr);
              var name = resData.words_result['单位名称'].words ? resData.words_result['单位名称'].words : '';
              var boss = resData.words_result['法人'].words ? resData.words_result['法人'].words : '';
              var company_address = resData.words_result['地址'].words ? resData.words_result['地址'].words : '';
              var company_idcard = resData.words_result['社会信用代码'].words ? resData.words_result['社会信用代码'].words : '';
              var company_period = resData.words_result['有效期'].words ? resData.words_result['有效期'].words : '';
              var create_time = resData.words_result['成立日期'].words ? resData.words_result['成立日期'].words : '';
              if (name != '' && name != '无') {
                _this.addData.name = name;
              }
              if (boss != '' && boss != '无') {
                _this.addData.boss = boss;
              }
              if (create_time != '' && create_time != '无') {
                _this.addData.create_time = create_time;
              }
              if (company_address != '' && company_address != '无') {
                _this.addData.company_address = company_address;
              }
              if (company_idcard != '' && company_idcard != '无') {
                _this.addData.company_idcard = company_idcard;
              }
              if (company_period != '' && company_period != '无') {
                _this.addData.company_period = company_period;
              }
            }
          } else {
            _this.$Message.error('识别营业执照信息失败!');
          }
        }
      },
      handleSearch () {
        var _this = this;
        _this.page = 1;
        var searchConName = _this.searchConName;
      },
      changePage (page) {
        var _this = this;
        console.log('page', page);
        _this.page = page;
        _this.getData();
      },
      onRowData: function (data, index) {
        var _this = this;
        _this.show(index, data);
      },
      show: function (index, data) {
        var _this = this;
        var id = data.id;
        _this.id = id;

        var data = {
          id: _this.id,
        };
        var params = {
          url: '/record/query',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data || [];
            var statusTitle = _data.status;
            switch (statusTitle) {
              case 'undistributed':
                statusTitle = '未分配';
                break;
              case 'undo':
                statusTitle = '未录入';
                break;
              case 'doing':
                statusTitle = '未完善';
                break;
              case 'done':
                statusTitle = '已完成';
                break;
              default:
                break;
            }
            _data.statusTitle = statusTitle;
            _this.dataDetail = _data;
            _this.showCurrentTableData = true;
          } else {
            _this.$Message.error('查询信息失败!');
          }
        }
      },
      asyncOK: function () {
        var _this = this;
        _this.showCurrentTableData = false;
      },
      // 显示任务分配
      showCommitteeModal: function () {
        var _this = this;
        var selectionArr = _this.selectionArr;
        if (selectionArr.length == 0) {
          _this.$Message.error('请填选择要分配的数据!');
          return false;
        }
        _this.CommitteeModal = true;
      },
      // 隐藏任务分配
      hideCommitteeModal: function () {
        var _this = this;
        _this.Committee_id = '';
        _this.CommitteeModal = false;
      },
      // 保存任务分配
      saveCommitteeData: function () {
        var _this = this;
        var Committee_id = _this.Committee_id;
        var selectionArr = _this.selectionArr;
        if (Committee_id == '') {
          _this.$Message.error('请填选择居委会!');
          return false;
        }
        var selectionIds = [];
        for (var k in selectionArr) {
          if (!selectionArr[k]) {
            continue;
          }
          var id = selectionArr[k].id;
          selectionIds.push(id);
        }
        var data = {
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
          department: Committee_id,
          company_id: selectionIds
        };
        var params = {
          url: '/record/distributionTask',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        _this.saveLoading = true;
        function _successFun(res) {
          _this.saveLoading = false;
          if (res.result == 0) {
            _this.hideCommitteeModal();
            _this.page = 1;
            _this.getData();
          } else {
            _this.$Message.error('保存信息失败!');
          }
        }
      },
      // 选中文件
      handleUpload_license: function (file) {
        var _this = this;
        _this.UploadFile('license', file);
        return false;
      },
      // 选中文件
      handleUpload_accessory: function (file) {
        var _this = this;
        _this.UploadFile('accessory', file);
        return false;
      },
      // 上传文件
      UploadFile: function (UploadType, file) {
        var _this = this;
        var name = file.name;
        var arr = name.split('.');
        var fileType = arr[arr.length - 1];
        if (!(Util.constant.format.indexOf(fileType) > -1)) {
          _this.$Message.error('请上传图片!');
          return false;
        }
        var formData = new FormData();
        formData.append("file", file);
        formData.append("type", "image");
        var params = {
          url: '/file/addFile',
          type: Util.method.post,
          data: formData,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var data = res.data;
            var id = data.id;
            var name = data.name;
            var url = data.url;
            var obj = {
              id: id,
              name: name,
              path: url,
            };
            if (UploadType == 'license') {
              _this.addData.license = [];
              _this.addData.license.push(obj);
              _this.getBusinessLicense(id);
            } else if (UploadType == 'accessory') {
              _this.addData.accessory.push(obj);
            }
          } else {
            _this.$Message.error('上传失败!');
          }
        }
      },
      // 删除附件
      delAccessory: function (UploadType, el) {
        var _this = this;
        var id = el.id;
        var fileArr = [];
        if (UploadType == 'license') {
          fileArr = _this.addData.license;
        } else if (UploadType == 'accessory') {
          fileArr = _this.addData.accessory;
        }
        for (var k in fileArr) {
          if (!fileArr[k]) {
            continue;
          }
          if (id == fileArr[k].id) {
            var del = fileArr.splice(k, 1);
            break;
          }
        }
        if (UploadType == 'license') {
          _this.addData.license = fileArr;
        } else if (UploadType == 'accessory') {
          _this.addData.accessory = fileArr;
        }
      },
      // 列表多选 选中数据
      selectionChange: function (selection) {
        var _this = this;
        _this.selectionArr = selection;
      },
      // 隐藏编辑页面
      hideAddModal: function () {
        var _this = this;
        _this.addCurrentTableData = false;
      },
      // 显示添加界面
      add: function () {
        var _this = this;
        _this.ajaxType = 'add';
        _this.addData.name = '';
        _this.addData.boss = '';
        _this.addData.mobile = '';
        _this.addData.scale = 0;
        _this.addData.create_time = '';
        _this.addData.company_address = '';
        _this.addData.company_idcard = '';
        _this.addData.company_period = '';
        _this.addData.license = [];
        _this.addData.accessory = [];
        _this.addData.is_complete = false;
        _this.addCurrentTableData = true;
      },
      // 保存数据
      save: function () {
        var _this = this;
        var name = _this.addData.name;
        var boss = _this.addData.boss;
        var mobile = _this.addData.mobile;
        var scale = _this.addData.scale;
        var create_time = _this.addData.create_time;
        var company_address = _this.addData.company_address;
        var company_idcard = _this.addData.company_idcard;
        var company_period = _this.addData.company_period;
        var license = _this.addData.license;
        var accessory = _this.addData.accessory;
        var is_complete = _this.addData.is_complete;
        if (name == '') {
          _this.$Message.error('请填写企业名称!');
          return false;
        }
        if (boss == '') {
          _this.$Message.error('请填写法人姓名!');
          return false;
        }
        if (mobile == '') {
          _this.$Message.error('请填写联系方式!');
          return false;
        }
        var license_id = '';
        for (var k in license) {
          if (!license[k]) {
            continue;
          }
          license_id = license[k].id;
        }
        var images = [];
        for (var k in accessory) {
          if (!accessory[k]) {
            continue;
          }
          images.push(accessory[k].id);
        }
        if (create_time && create_time != '') {
          create_time = Utils.dateToDateString(create_time);
        }
        if (company_period && company_period != '') {
          company_period = Utils.dateToDateString(company_period);
        }
        var data = {
          id: _this.id,
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
          name: name,
          boss: boss,
          mobile: mobile,
          scale: scale,
          create_time: create_time,
          company_address: company_address,
          company_idcard: company_idcard,
          company_period: company_period,
          license: license_id,
          accessory: images,
          is_complete: is_complete,
        };
        var url = '/record/addCompany';
        if (_this.ajaxType == 'update') {
          url = '/record/updateCompany';
        }
        var params = {
          url: url,
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        _this.saveLoading = true;
        function _successFun(res) {
          _this.saveLoading = false;
          if (res.result == 0) {
            _this.page = 1;
            _this.getData();
            _this.addData.name = '';
            _this.addData.boss = '';
            _this.addData.mobile = '';
            _this.addData.scale = 0;
            _this.addData.create_time = '';
            _this.addData.company_address = '';
            _this.addData.company_idcard = '';
            _this.addData.company_period = '';
            _this.addData.license = [];
            _this.addData.accessory = [];
            _this.addData.is_complete = false;
            _this.hideAddModal();
          } else {
            _this.$Message.error('保存信息失败!');
          }
        }

      },
      // 显示修改界面
      update: function (data, index) {
        var _this = this;
        _this.ajaxType = 'update';
        var id = data.id;
        _this.id = id;
        var data = {
          id: _this.id,
        };
        var params = {
          url: '/record/query',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data || [];
            _this.addData.name = _data.name;
            _this.addData.boss = _data.boss;
            _this.addData.mobile = _data.mobile;
            _this.addData.scale = _data.scale > 0 ? _data.scale : 0;
            _this.addData.create_time = _data.create_time;
            _this.addData.company_address = _data.company_address;
            _this.addData.company_idcard = _data.idcard;
            _this.addData.company_period = _data.period;
            _this.addData.license = _data.license;
            _this.addData.accessory = _data.accessory;
            _this.addData.is_complete = false;
            _this.addCurrentTableData = true;
          } else {
            _this.$Message.error('查询信息失败!');
          }
        }
      },
      // 删除
      remove: function () {
        var _this = this;
        var selectionArr = _this.selectionArr;
        if (selectionArr.length == 0) {
          _this.$Message.error('请填选择要删除的数据!');
          return false;
        }
        var selectionIds = [];
        for (var k in selectionArr) {
          if (!selectionArr[k]) {
            continue;
          }
          var id = selectionArr[k].id;
          selectionIds.push(id);
        }
        Modal.confirm(_this, {content: '确定删除选中的信息？'}, function () {
          var data = {
            id: selectionIds,
          };
          var params = {
            url: '/record/deleteMultiple',
            type: Util.method.get,
            data: data,
            success: _successFun
          };
          Util.ajax(_this, params);
          function _successFun(res) {
            if (res.result == 0) {
              _this.page = 1;
              _this.getData();
            } else {
              _this.$Message.error('删除信息失败!');
            }
          }
        }, function () {
        });
      },
      // 导出
      ExportData: function () {
        var _this = this;
        var fields = [
          {
            field: 'cname',
            title: '企业名称',
            type: 'varchar',
            order: 1,
          },
          {
            field: 'legal_person',
            title: '法人',
            type: 'varchar',
            order: 2,
          },
          {
            field: 'idcard',
            title: '营业执照编号',
            type: 'varchar',
            order: 3,
          },
          {
            field: 'scale',
            title: '企业规模',
            type: 'varchar',
            order: 4,
          },
          {
            field: 'net_worth',
            title: '净资产',
            type: 'varchar',
            order: 5,
          },
          {
            field: 'create_time',
            title: '企业创立时间',
            type: 'varchar',
            order: 6,
          },
          {
            field: 'period',
            title: '有效期',
            type: 'varchar',
            order: 7,
          },
          {
            field: 'company_address',
            title: '企业地址',
            type: 'varchar',
            order: 8,
          },
          {
            field: 'mobile',
            title: '手机号',
            type: 'varchar',
            order: 9,
          },
          {
            field: 'status',
            title: '信息采集状态',
            type: 'varchar',
            order: 10,
          },
        ];
        var fieldsStr = Util.toStr(fields);
        var data = {
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
          type: 'company',
          fields: fieldsStr,
        };
        var params = {
          url: '/file/db2excle',
          type: Util.method.post,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var url = res.data;
            var date = Utils.dateToDateString(new Date());
            Utils.DownloadFile(url, '导出经济档案信息_' + date + '.xlsx');
          } else {
            _this.$Message.error('导出信息失败!');
          }
        }
      },
      // 导入
      importData: function () {
        var _this = this;
        _this.importDataArr = [];
        _this.ImportDataColumns = [];
        _this.ImportData = [];
        _this.importDataModal = true;
      },
      // 取消导入
      hideImportDataModal: function () {
        var _this = this;
        _this.importDataArr = [];
        _this.ImportDataColumns = [];
        _this.ImportData = [];
        _this.importDataModal = false;
      },
      // 确定导入
      saveImportData: function () {
        var _this = this;
        if (_this.importDataArr.length == 0) {
          _this.$Message.error('请上传附件!');
          return false;
        }
        var file_id = _this.importDataArr[0].id;
        var data = {
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
          fid: file_id
        };
        var params = {
          url: '/record/importExcel',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            _this.page = 1;
            _this.getData();
            _this.hideImportDataModal();
          } else {
            _this.$Message.error('导入信息失败!');
          }
        }
      },
      // 选中文件
      ImportDatahandleUpload: function (file) {
        var _this = this;
        _this.ImportDataUploadFile(file);
        return false;
      },
      // 上传文件
      ImportDataUploadFile: function (file) {
        var _this = this;
        var name = file.name;
        var arr = name.split('.');
        var type = arr[1];
        if (type != 'xlsx') {
          _this.$Message.error('请上传xlsx文件!');
          return false;
        }
        var formData = new FormData();
        formData.append("file", file);
        formData.append("action", "UploadVMKImagePath");
        var params = {
          url: '/file/addFile',
          type: Util.method.post,
          data: formData,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var data = res.data;
            var id = data.id;
            var name = data.name;
            var url = data.url;
            var obj = {
              id: id,
              name: name,
              url: url,
            };
            _this.importDataArr.push(obj);
            _this.getImportData(id);// 预览
          } else {
            _this.$Message.error('上传失败!');
          }
        }
      },
      // 删除附件
      ImportDatadelimportData: function (el) {
        var _this = this;
        var id = el.id;
        var importDataArr = _this.importDataArr;
        for (var k in importDataArr) {
          if (!importDataArr[k]) {
            continue;
          }
          if (id == importDataArr[k].id) {
            var del = importDataArr.splice(k, 1);
            break;
          }
        }
        _this.importDataArr = importDataArr;
        _this.ImportDataColumns = [];
        _this.ImportData = [];
      },
      // 预览数据
      getImportData: function (file_id) {
        var _this = this;
        if (!file_id) {
          return;
        }
        var data = {
          fid: file_id,
          lines: 10,
        };
        var params = {
          url: '/file/exclePreview',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data;
            var ImportDataColumns = [];
            var ImportData = [];
            if (_data.length > 0) {
              var Sheet1_data = _data[0].data;
              if (Sheet1_data.length > 0) {
                // 表头
                var titleArr = Sheet1_data[0];
                for (var t in titleArr) {
                  if (!titleArr[t]) {
                    continue;
                  }
                  var col = titleArr[t].col;
                  var title = titleArr[t].title;
                  var Columns = {
                    key: 'key_' + title + '_' + col,
                    title: title,
                    width: 150,
                  };
                  ImportDataColumns.push(Columns);
                }
                // 数据
                for (var k in Sheet1_data) {
                  if (!Sheet1_data[k]) {
                    continue;
                  }
                  var dataObj = {};
                  var dataArr = Sheet1_data[k];
                  for (var r in dataArr) {
                    if (!dataArr[r]) {
                      continue;
                    }
                    var col = dataArr[r].col;
                    var title = dataArr[r].title;
                    var value = dataArr[r].value;
                    var key = 'key_' + title + '_' + col;
                    dataObj[key] = value;
                  }
                  if (Object.keys(dataObj).length > 0) {
                    ImportData.push(dataObj);
                  }
                }
              }
            }
            _this.ImportDataColumns = ImportDataColumns;
            _this.ImportData = ImportData;
          } else {
            _this.$Message.error('预览信息失败!');
          }
        }
      },
    }
  };
</script>
